package com.xjrsoft.common.serializers;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.sql.Blob;
import java.sql.SQLException;
import java.time.LocalDateTime;

@Slf4j
public class BlobSerializer extends JsonSerializer<Blob> {
    @Override
    public void serialize(Blob value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        try {
            gen.writeString(new String(value.getBytes(1, (int)value.length()), "UTF-8"));
        } catch (SQLException e) {
            log.error("Blob类型数据序列化失败！", e);
        }
    }
}
